;define(function (require, exports, module) {
    'use strict';
    //obj dialog节点对象，确定按钮触发事件
    var showDialog = function (obj, okFn) {
//      obj.css("margin-top","-"+obj.height()/2+"px");
//      obj.css("margin-left","-"+obj.width()/2+"px");
        obj.removeClass("none");
        $("#fullBg").removeClass("none");
        var $handBtn = obj.find(".dialogHandlerBtn");
        var $cancelBtn = obj.find(".dialogCancelBtn");
        $handBtn.unbind("click").click(function(){
        	if(okFn!=null && okFn!=undefined){
        		 okFn();
        	}
           
        })
        $cancelBtn.unbind("click").click(function () {
            hideDialog(obj);
        });
        $(".closeDiv").unbind("click").click(function(){
            hideDialog(obj);
        })
        dragDialog(obj);
    };
    var hideDialog = function (obj) {
    	$("#popdialog").html("");
    	$("#popdialog1").html("");
        $("#loading").addClass("none");
        obj.addClass("none");
        $("#fullBg").addClass("none");
        dialogClear(obj);
    };
    
    var dragDialog = function(obj){
    	/**
		   拖拽div
		   关键事件:mouseDown, mouseMove,mouseUp
		**/
		 
		var params={
		    top:0,
		    left:0,
		    currentX:0,
		    currentY:0,
		    flag:false
		};
		
		/**
		obj.currentStyle[attr]
		getComputedStyle(obj,false)[attr] 获取DOM非行间样式
		**/
		var getCss=function(o,key){
		    return o.currentStyle ? o.currentStyle[key] : document.defaultView.getComputedStyle(o,false)[key];
		}
		
		var startDrag=function(bar,target,callback){
		    if(getCss(target,'left')!='auto'){
		        params.left=getCss(target,'left');
		    }
		    if(getCss(target,'top')!='auto'){
		        params.top=getCss(target,'top');
		    }
		    bar.onmousedown=function(event){
		        params.flag=true;
		        if(!event){
		            event=window.even;
		            bar.onselectstart=function(){ //IE和Chrome适用，防止内容被选中默认是true
		                return false;
		            }
		        }
		        var e=event;
		        params.currentX=e.clientX;
		        params.currentY=e.clientY;
		    }
		     
		    document.onmouseup=function(){
		        params.flag=false;
		        if(getCss(target,"left") !='auto'){
		            params.left=getCss(target,'left');
		        }
		        if(getCss(target,'top') !='auto'){
		            params.top=getCss(target,'top');
		        }
		    }
		    document.onmousemove=function(event){
		        var e=event?event:window.event;
		        if(params.flag){
		            var nowX=e.clientX,nowY=e.clientY;
		            var disX=nowX-params.currentX, disY=nowY-params.currentY;
		            target.style.left=parseInt(params.left)+disX+'px';
		            target.style.top=parseInt(params.top)+disY+'px';
		        }
		         
		        if(callback=='function'){
		            callback(parseInt(params.left)+disX,parseInt(params.top)+disY);
		        }
		    }
		}
		
		var box = $(obj)[0];
		var bar = $(obj).find(".dialogTitle")[0];
		startDrag(bar,box);
    }
    
    var hideSelfDialog = function(obj){
    	obj.addClass("none");
    }
    //普通确认框
    var showConfirmDialog = function (title,con,okFn) {
        var obj = $("#confirmDialog");
        obj.find(".dialogTitle").html(title);
        obj.find(".dialogContent").html(con);
        obj.removeClass("none");
        $("#fullBg").removeClass("none");
        var $handBtn = obj.find(".dialogHandlerBtn");
        var $cancelBtn = obj.find(".dialogCancelBtn");
        var $closeBtn = obj.find(".closeDiv");
        $handBtn.unbind("click").click(function(){
            obj.addClass("none");
            $("#fullBg").addClass("none");
            okFn();
        })
        $cancelBtn.unbind("click").click(function () {
            hideDialog(obj);
        });
        $closeBtn.unbind("click").click(function () {
            hideDialog(obj);
        });
        
        dragDialog(obj);
    };
    //清除输入框内容
    var dialogClear = function(obj){
        var inputs = obj.find("input[type=text],input[type=password],textarea");
        for(var i = 0;i<inputs.length;i++){
            inputs[i].value = "";
        }
        obj.find("form .error").html("");
    };
    return {
        showDialog:showDialog,
        hideDialog:hideDialog,
        showConfirmDialog:showConfirmDialog,
        dialogClear:dialogClear,
        hideSelfDialog: hideSelfDialog
    };
});